<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"theeyaesakura.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="参照官方文档做的笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="RT-Thread内核学习">
<meta property="og:url" content="https://theeyaesakura.gitee.io/2020/12/08/rt-thread-kernel/index.html">
<meta property="og:site_name" content="SOME">
<meta property="og:description" content="参照官方文档做的笔记">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://theeyaesakura.gitee.io/2020/12/08/rt-thread-kernel/rt-thread-kernel/1602053794954.png">
<meta property="article:published_time" content="2020-12-08T02:31:39.000Z">
<meta property="article:modified_time" content="2021-03-05T11:20:11.848Z">
<meta property="article:author" content="茶沉小团月">
<meta property="article:tag" content="RT-Thread">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://theeyaesakura.gitee.io/2020/12/08/rt-thread-kernel/rt-thread-kernel/1602053794954.png">

<link rel="canonical" href="https://theeyaesakura.gitee.io/2020/12/08/rt-thread-kernel/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>RT-Thread内核学习 | SOME</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="SOME" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">SOME</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">学习记录</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://theeyaesakura.gitee.io/2020/12/08/rt-thread-kernel/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/2.jpg">
      <meta itemprop="name" content="茶沉小团月">
      <meta itemprop="description" content="Just For Fun">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SOME">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
		  RT-Thread内核学习
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-12-08 10:31:39" itemprop="dateCreated datePublished" datetime="2020-12-08T10:31:39+08:00">2020-12-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-03-05 19:20:11" itemprop="dateModified" datetime="2021-03-05T19:20:11+08:00">2021-03-05</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E4%B9%A0/" itemprop="url" rel="index"><span itemprop="name">学习</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.2k</span>
            </span>
            <div class="post-description">参照官方文档做的笔记</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="内核各个文件"><a href="#内核各个文件" class="headerlink" title="内核各个文件"></a>内核各个文件</h3><table>
<thead>
<tr>
<th>文件名</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>kservice.c</td>
<td>内核库、提供c库的函数</td>
</tr>
<tr>
<td>object.c</td>
<td>对象管理</td>
</tr>
<tr>
<td>schedule.c</td>
<td>实时调度器</td>
</tr>
<tr>
<td>thread.c</td>
<td>线程管理</td>
</tr>
<tr>
<td>ipc.c</td>
<td>线程间通信</td>
</tr>
<tr>
<td>clock.c、timer.c</td>
<td>时钟管理</td>
</tr>
<tr>
<td>mem.c等</td>
<td>内存管理</td>
</tr>
<tr>
<td>device.c</td>
<td>设备管理</td>
</tr>
</tbody></table>
<h3 id="RT-Thread程序内存分布"><a href="#RT-Thread程序内存分布" class="headerlink" title="RT-Thread程序内存分布"></a>RT-Thread程序内存分布</h3><ul>
<li>code：代码段，存放程序代码</li>
<li>RO-data：只读数据段，存放程序中定义的常量 const；</li>
<li>RW-data：读写程序段，存放初始化为非0的全局变量 static</li>
<li>ZI-data：零数据段，存放未初始化的全局变量及初始化为0的变量</li>
</ul>
<h3 id="线程管理"><a href="#线程管理" class="headerlink" title="线程管理"></a>线程管理</h3><h4 id="功能特点"><a href="#功能特点" class="headerlink" title="功能特点"></a>功能特点</h4><ol>
<li>抢占式线程调度器，从就绪列表中找到优先级最高的线程，保证优先级最高的线程能够被运行，最高优先的线程一旦就绪，总能得到CPU的使用权</li>
<li>一个运行着的线程使一个比它优先级高的线程满足运行条件，就会让出使用权</li>
<li>中断服务程序使一个高优先级的线程满足运行条件，中断完成时，被中断的线程挂起，优先级高的线程开始运行</li>
<li>当线程调度器线程切换时，先将当前线程上下文保存起来，当再切回到这个线程时，线程调度器恢复该线程上下文信息</li>
</ol>
<h4 id="线程工作机制"><a href="#线程工作机制" class="headerlink" title="线程工作机制"></a>线程工作机制</h4><h5 id="线程控制块"><a href="#线程控制块" class="headerlink" title="线程控制块"></a>线程控制块</h5><p>​        使用<code>struct rt_thread</code>表示，线程控制块是操作系统用于管理线程的数据结构；</p>
<p>​        存放一些线程信息:优先级、线程名称、线程状态等；</p>
<p>​        还包含线程间连接的链表结构，事件等集合。</p>
<h5 id="线程重要属性"><a href="#线程重要属性" class="headerlink" title="线程重要属性"></a>线程重要属性</h5><h6 id="线程栈"><a href="#线程栈" class="headerlink" title="线程栈"></a>线程栈</h6><ul>
<li>进行线程切换时，会将当前线程的上下文保存在栈中，当线程恢复运行时，再从栈中读取上下文信息，进行恢复</li>
<li> 线程栈还用于存放函数中的局部变量</li>
</ul>
<h6 id="线程状态"><a href="#线程状态" class="headerlink" title="线程状态"></a>线程状态</h6><ul>
<li>初始状态</li>
<li>就绪状态</li>
<li>运行状态</li>
<li>挂起状态</li>
<li>关闭状态</li>
</ul>
<h6 id="线程优先级"><a href="#线程优先级" class="headerlink" title="线程优先级"></a>线程优先级</h6><ul>
<li>表示线程被调度的优先程度。</li>
<li>最大支持256个优先级。在CM系列中，常用32个优先级。</li>
<li>最低优先级的线程默认分配给空闲线程使用。</li>
</ul>
<h6 id="时间片"><a href="#时间片" class="headerlink" title="时间片"></a>时间片</h6><ul>
<li>每个线程都有时间片，但时间片仅对优先级相同的线程有效。</li>
<li>系统对优先级相同的就绪状态线程采用时间片轮转的方式调度</li>
<li>时间片起着约束线程单次运行时长的作用，单位是<code>OS tick</code></li>
</ul>
<h6 id="线程入口函数"><a href="#线程入口函数" class="headerlink" title="线程入口函数"></a>线程入口函数</h6><ul>
<li><p>线程控制块中entry是线程的入口函数,他是线程实现预期功能的函数。线程入口函数有用户设计实现</p>
<ul>
<li><p>无线循环模式</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">thread_entry</span><span class="params">(<span class="keyword">void</span> * parameter)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> 	<span class="keyword">while</span>(<span class="number">1</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">/* 等待时间发生 */</span></span><br><span class="line">        <span class="comment">/* 对事件进行服务、处理 */</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>不能进入死循环模式，必须有让出CPU使用权的操作，如：循环中调用延时或者主动挂起。</p>
</li>
<li><p>顺序执行或有限次循环</p>
 <figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">thread_entry</span><span class="params">(<span class="keyword">void</span>*parameter)</span></span></span><br><span class="line"><span class="function">		</span>&#123;</span><br><span class="line">	</span><br><span class="line">		&#125;</span><br></pre></td></tr></table></figure>

<p> 由系统自动删除</p>
</li>
</ul>
<h6 id="线程错误码"><a href="#线程错误码" class="headerlink" title="线程错误码"></a>线程错误码</h6><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EOK           0 <span class="comment">/* 无错误     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_ERROR         1 <span class="comment">/* 普通错误     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_ETIMEOUT      2 <span class="comment">/* 超时错误     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EFULL         3 <span class="comment">/* 资源已满     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EEMPTY        4 <span class="comment">/* 无资源     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_ENOMEM        5 <span class="comment">/* 无内存     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_ENOSYS        6 <span class="comment">/* 系统不支持     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EBUSY         7 <span class="comment">/* 系统忙     */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EIO           8 <span class="comment">/* IO 错误       */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EINTR         9 <span class="comment">/* 中断系统调用   */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> RT_EINVAL       10 <span class="comment">/* 非法参数      */</span></span></span><br></pre></td></tr></table></figure>



</li>
</ul>
<h5 id="线程状态切换"><a href="#线程状态切换" class="headerlink" title="线程状态切换"></a>线程状态切换</h5><p><img src="/2020/12/08/rt-thread-kernel/rt-thread-kernel/1602053794954.png"></p>
<ol>
<li><p>线程通过调用函数 <code>rt_thread_create/init()</code> 进入到初始状态 <code>RT_THREAD_INIT</code>;</p>
</li>
<li><p>初始状态的线程通过调用函数 <code>rt_thread_startup()</code> 进入到就绪状态 <code>RT_THREAD_READY</code>;</p>
</li>
<li><p>就绪状态的线程被调度器调度后进入运行状态 <code>RT_THREAD_RUNNING</code>;</p>
</li>
<li><p>处于运行状态的线程调用 <code>rt_thread_delay()、rt_sem_take()、rt_mutex_take()、rt_mb_rev()</code>等函数或者获取不到资源时，将进入挂起状态 <code>RT_THREAD_SUSPEND</code></p>
</li>
<li><p>处于挂起状态的线程，如果等待超时或者未能获得资源或由于其他线程释放了资源，那么他将回到就绪状态。调用 <code>rt_thread_delete/detach()</code>函数，将更改为关闭状态 <code>RT_THREAD_CLOSE</code>;</p>
</li>
<li><p>运行状态的线程，如果运行结束，就会在线程的最后部分执行 <code>rt_thread_exit()</code>函数，将状态更改为关闭状态</p>
</li>
<li><p><strong>注意！</strong> RT-Thread中实际上不存在运行状态，就绪状态和运行状态是等同的。</p>
</li>
</ol>
<h5 id="系统线程"><a href="#系统线程" class="headerlink" title="系统线程"></a>系统线程</h5><p>系统线程是指由系统创建的线程，用户线程是有用户程序调用线程管理接口创建的线程，在RT-Thread内核中的系统线程有空闲线程与主线程。</p>
<h6 id="空闲线程"><a href="#空闲线程" class="headerlink" title="空闲线程"></a>空闲线程</h6><p>空闲线程是系统创建的优先级最低的一个线程，永远为就绪状态。</p>
<p>当系统中无其他就绪线程时，调度器将调度到空闲线程，它通常是个死循环，且永远不被挂起。</p>
<p>在RTT中有特殊用途：</p>
<ul>
<li>若某线程执行完毕，系统将自动删除线程：自动执行 <code>rt_thread_exit()</code>函数，先将该线程从系统就绪队列中删除，再将该线程状态改为关闭状态，不再参与系统调度，然后挂入 <code>rt_thread_defunct</code>僵尸队列(资源未回收，处于关闭状态的线程队列)中，最后空闲线程会回收被删除线程的资源。</li>
<li>运行用户设置的钩子函数，在空闲线程运行时会调用该钩子函数，适合钩入功耗管理、看门狗喂狗等工作</li>
</ul>
<h6 id="主线程"><a href="#主线程" class="headerlink" title="主线程"></a>主线程</h6><ul>
<li>  系统启动时，系统会创建main线程，入口函数为 <code>main_thread_entry()</code>，用户的应用入口函数<code>main()</code>从这里真正开始，用户可以在 <code>main（）</code>函数中添加自己的初始化代码</li>
</ul>
<h4 id="线程管理的方式"><a href="#线程管理的方式" class="headerlink" title="线程管理的方式"></a>线程管理的方式</h4><p>创建动态线程 <code>rt_thread_create()</code>  创建静态线程 <code>rt_thread_init()</code></p>
<h5 id="创建和删除线程"><a href="#创建和删除线程" class="headerlink" title="创建和删除线程"></a>创建和删除线程</h5><p>一个线程要成为可执行的对象，就必须由操作系统的内核来为它创建一个线程。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">rt_thread_t</span> <span class="title">rt_thread_create</span><span class="params">(<span class="keyword">const</span> <span class="keyword">char</span>*name,</span></span></span><br><span class="line"><span class="function"><span class="params">                         <span class="keyword">void</span> (*entry)(<span class="keyword">void</span>* parameter),                          </span></span></span><br><span class="line"><span class="function"><span class="params">                         <span class="keyword">void</span> *parameter,</span></span></span><br><span class="line"><span class="function"><span class="params">                         <span class="keyword">rt_uint32_t</span> stack_size,</span></span></span><br><span class="line"><span class="function"><span class="params">                         <span class="keyword">rt_uint8_t</span> priority,</span></span></span><br><span class="line"><span class="function"><span class="params">                         <span class="keyword">rt_uint32_t</span> tick)</span></span>;</span><br></pre></td></tr></table></figure>

<p>系统会从动态堆内存中分配一个线程句柄，以及按照参数中指定的栈大小分配相应的空间</p>
<table>
<thead>
<tr>
<th align="left">参数</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">name</td>
<td>线程的名称；线程名称的最大长度由rtconfig.h中的宏RT_NAME_MAX定义，多余部分会自动截掉</td>
</tr>
<tr>
<td align="left">entry</td>
<td>线程入口函数</td>
</tr>
<tr>
<td align="left">parameter</td>
<td>线程入口函数参数</td>
</tr>
<tr>
<td align="left">stack_size</td>
<td>线程栈大小，单位是字节</td>
</tr>
<tr>
<td align="left">priority</td>
<td>线程的优先级。优先级范围根据系统配置情况(rtconfig.h中的RT_THREAD_PRIORITY_MAX定义),如果支持的是256级优先级，那么范围是从0~255，数值越小优先级越高，0代表最高优先级</td>
</tr>
<tr>
<td align="left">tick</td>
<td>线程时间片大小。时间片的单位是操作系统的时钟节拍。当系统中存在相同优先级的线程时，这个参数指定线程一次调度能够运行的最大时间长度。这个时间片运行结束时，调度器自动选择下一个就绪态的同优先级线程进行运行</td>
</tr>
<tr>
<td align="left">返回</td>
<td></td>
</tr>
<tr>
<td align="left">thread</td>
<td>线程创建成功，返回线程句柄</td>
</tr>
<tr>
<td align="left">RT_NULL</td>
<td>线程创建失败</td>
</tr>
</tbody></table>
<p>对于使用rt_thread_create()创建出来的线程，当不需要使用，或者运行出错是，可以使用下面的函数接口来从系统中把线程完全删除掉：</p>
<p><code>rt_err_t rt_thread_delete(rt_thread_t thread)</code></p>
<p>调用该函数后，线程对象会被移出线程队列，并且从内核对象中删除，释放掉线程占用的堆栈空间，收回来将用于其他内存分配。</p>
<p><strong>注意：rt_thread_delete()是将thread变为CLOSE状态，放入rt_thread_defunct队列中;真正的删除动作(释放线程和释放线程栈)需要到下一次执行空闲线程时，由空闲线程完成最后的线程删除动作。</strong></p>
<h5 id="初始化和脱离线程"><a href="#初始化和脱离线程" class="headerlink" title="初始化和脱离线程"></a>初始化和脱离线程</h5>
    </div>

    
    
    
	<div>
		
			<div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------THE END-------------</div>
    
</div>

		
	</div>
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/images/wechat_channel.jpg">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </a>
        </div>

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/RT-Thread/" rel="tag"># RT-Thread</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item"></div>
      <div class="post-nav-item">
    <a href="/2020/12/08/%E4%B8%80%E4%BA%9B%E5%AD%A6%E4%B9%A0%E8%BF%87%E7%A8%8B%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" rel="next" title="一些学习过程中遇到的常用命令">
      一些学习过程中遇到的常用命令 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%86%85%E6%A0%B8%E5%90%84%E4%B8%AA%E6%96%87%E4%BB%B6"><span class="nav-number">1.</span> <span class="nav-text">内核各个文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RT-Thread%E7%A8%8B%E5%BA%8F%E5%86%85%E5%AD%98%E5%88%86%E5%B8%83"><span class="nav-number">2.</span> <span class="nav-text">RT-Thread程序内存分布</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E7%AE%A1%E7%90%86"><span class="nav-number">3.</span> <span class="nav-text">线程管理</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8A%9F%E8%83%BD%E7%89%B9%E7%82%B9"><span class="nav-number">3.1.</span> <span class="nav-text">功能特点</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E5%B7%A5%E4%BD%9C%E6%9C%BA%E5%88%B6"><span class="nav-number">3.2.</span> <span class="nav-text">线程工作机制</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E6%8E%A7%E5%88%B6%E5%9D%97"><span class="nav-number">3.2.1.</span> <span class="nav-text">线程控制块</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E9%87%8D%E8%A6%81%E5%B1%9E%E6%80%A7"><span class="nav-number">3.2.2.</span> <span class="nav-text">线程重要属性</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E6%A0%88"><span class="nav-number">3.2.2.1.</span> <span class="nav-text">线程栈</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E7%8A%B6%E6%80%81"><span class="nav-number">3.2.2.2.</span> <span class="nav-text">线程状态</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E4%BC%98%E5%85%88%E7%BA%A7"><span class="nav-number">3.2.2.3.</span> <span class="nav-text">线程优先级</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E6%97%B6%E9%97%B4%E7%89%87"><span class="nav-number">3.2.2.4.</span> <span class="nav-text">时间片</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E5%85%A5%E5%8F%A3%E5%87%BD%E6%95%B0"><span class="nav-number">3.2.2.5.</span> <span class="nav-text">线程入口函数</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E9%94%99%E8%AF%AF%E7%A0%81"><span class="nav-number">3.2.2.6.</span> <span class="nav-text">线程错误码</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E7%8A%B6%E6%80%81%E5%88%87%E6%8D%A2"><span class="nav-number">3.2.3.</span> <span class="nav-text">线程状态切换</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%B3%BB%E7%BB%9F%E7%BA%BF%E7%A8%8B"><span class="nav-number">3.2.4.</span> <span class="nav-text">系统线程</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%A9%BA%E9%97%B2%E7%BA%BF%E7%A8%8B"><span class="nav-number">3.2.4.1.</span> <span class="nav-text">空闲线程</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E4%B8%BB%E7%BA%BF%E7%A8%8B"><span class="nav-number">3.2.4.2.</span> <span class="nav-text">主线程</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BA%BF%E7%A8%8B%E7%AE%A1%E7%90%86%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="nav-number">3.3.</span> <span class="nav-text">线程管理的方式</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E5%92%8C%E5%88%A0%E9%99%A4%E7%BA%BF%E7%A8%8B"><span class="nav-number">3.3.1.</span> <span class="nav-text">创建和删除线程</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%88%9D%E5%A7%8B%E5%8C%96%E5%92%8C%E8%84%B1%E7%A6%BB%E7%BA%BF%E7%A8%8B"><span class="nav-number">3.3.2.</span> <span class="nav-text">初始化和脱离线程</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="茶沉小团月"
      src="/images/2.jpg">
  <p class="site-author-name" itemprop="name">茶沉小团月</p>
  <div class="site-description" itemprop="description">Just For Fun</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">8</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/JaminLeeMJ" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;JaminLeeMJ" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1097282916@qq.com" title="E-Mail → mailto:1097282916@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://yoursite.com/" title="http:&#x2F;&#x2F;yoursite.com" rel="noopener" target="_blank">Title</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>
    <footer class="footer">
      <div class="footer-inner">
        

        
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">茶沉小团月</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">19k</span>
</div>
<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共7.7k字</span>
</div>


<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>
</div>


        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>















  

  

</body>
</html>
<script type="text/javascript" src="/js/clicklove.js"></script>
<!-- 动态背景 -->
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

